package com.fdk.wms.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fdk.wms.common.R;
import com.fdk.wms.entity.Book;
import com.fdk.wms.service.BookService;



@RestController
@RequestMapping("/book")
public class BookController {
    @Autowired
    private BookService bookService;

    @GetMapping("/bookList")
    public R<List<Book>> BookList(){
        List<Book> books = bookService.findAllBooks();
        return R.success(books, "success");

    }

    @PostMapping("/addBook")
    public R<String> addBook(@RequestBody Book book){
        try {
            bookService.insertBook(book);
            return R.success(null, "新增成功");
        } catch (Exception e) {
            return R.error("新增失败:"+e, 201);
        }
    }

}
